home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / GCD.ICN < prev    next >
Text File  |  1992-09-28  |  759b  |  33 lines

  1. ############################################################################
  2. #
  3. #    File:     gcd.icn
  4. #
  5. #    Subject:  Procedures to compute greatest common denominator
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 11, 1989
  10. #
  11. ###########################################################################
  12. #
  13. #     This procedure computes the greatest common denominator of two
  14. #  integers. If both are zero, it fails.
  15. #
  16. ############################################################################
  17.  
  18. procedure gcd(i,j)
  19.    local r
  20.  
  21.    if i = j = 0 then fail
  22.    if i = 0 then return j
  23.    if j = 0 then return i
  24.    i := abs(i)
  25.    j := abs(j)
  26.    repeat {
  27.       r := i % j
  28.       if r = 0 then return j
  29.       i := j
  30.       j := r
  31.       }
  32. end
  33.